﻿'----------------------------------------------
'   
'   Kernel Info:---------------------------
'   Developer:              Joshua Teeter
'   Genesis:                09-02-08
'   Last Update:            09-06-22
'   Origional Version:      0.0.0.0
'   Current Version:        0.0.0.7
'   ---------------------------------------
'   
'   
'   If you modify this code please leave your name in the modified by list seperated by a comma. 
'   Changes are to be denoted in the following manner:
'                                                       * New
'                                                       ^ Updated
'                                                       - Removed
'                                                       + Added Functionality
'                                                       ! Bug unresolved
'                                                       / Bug resolved
'                                                       % Modified but not changed in a noticeable way in terms of functionality
'  
'  Please use the following as a template and copy and paste as a new comment for each modification.
'   
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            NULL
'   Last Update:            NULL
'   Current Version:        #.#.#.#
'   Changes:                 NULL
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-11
'   Current Version:        0.0.0.1
'   Changes:                 *+ Added click on text box to launch a OFD
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-04-26
'   Current Version:        0.0.0.2
'   Changes:                 * This is a large update
'                           % Added more commenting
'                           / Fixed issue when choosing cancel, the times are update anyways.
'                           - Old three text boxes for h/m/s and AM/PM have been replaced with date time picker
'                           *+ Date time picker
'                           + Added ability to add paths other than directories and files (e.g. http://sourceforge.com)
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-05-05
'   Current Version:        0.0.0.3
'   Changes:                 % Major update
'                           + Added ability to change enabled status
'                           * Graphical change to form. Added new Enabled check box for each day.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-05-25
'   Current Version:        0.0.0.4
'   Changes:                / Fixed an oversight in the way things were setup. Enabled status is now default to on.
'                           / Fixed critical bug found by pressing cancel, causing ATEA to attempt to update crashing the application.
'                             The bug can no longer be replicated. It would only happen if someone chose the add an application and then canceled.
'                           / Fixed bug with timing causing values that were impossible. e.g. 11:69:00 PM instead of 12:59:00 AM which makes more sense.
'                             As a result there are more in depth instructions on how this works in the actual function.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-05-29
'   Current Version:        0.0.0.5
'   Changes:                / Fixed the worst spelling error to not be caught ever. Thanks Dana H for the catch!
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-06-03
'   Current Version:        0.0.0.6
'   Changes:                + Changed the layout of the settings form
'                           * Added skin settings
'                           + Made the labels more direct in meaning
'                           ^ Made "Update one day only" to say the day it is updating. e.g. "Update sunday only"
'                             Also changed the text to read differently if Update all days was selected.
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-06-22
'   Current Version:        0.0.0.7
'   Changes:                * Added option for "start with windows" or "start on timer" option when form loads
'                           * Added ability to start items with windows (batch file creation)
'   ---------------------------------------
'   Modification Info:---------------------
'   Class Name:             Setting.vb
'   Modified by:            Joshua Teeter
'   Last Update:            09-06-30
'   Current Version:        0.0.0.8
'   Changes:                + Made font all one size, and update the text to better represent function.
'   ---------------------------------------
'
'

Public Class Setting

    '
    ' This is used to determine if cancel was pressed
    '
    Private passed As Boolean = False

    '
    ' These are temp values to stand in for ATEA while chaning settings.
    '
    Protected Friend tempName As String
    Protected Friend tempArg As String
    Protected Friend tempTime As SMTWTFS
    Protected Friend tempTime2 As New SMTWTFS
    Protected Friend tempEnabled As Boolean
    Protected Friend time As Boolean

    Private Sub skin()

        Dim buttons As New List(Of Button)
        Dim labels As New List(Of Label)
        Dim textboxes As New List(Of TextBox)
        Dim rbuttons As New List(Of RadioButton)
        Dim checkboxex As New List(Of CheckBox)
        Dim groupboxes As New List(Of GroupBox)
        Dim comboboxes As New List(Of ComboBox)

        With buttons
            .Add(btnCancel)
            .Add(btnGetPath)
            .Add(btnSet)
            .Add(btnTime)
            .Add(btnWindows)
        End With

        With labels
            .Add(lblArguments)
            .Add(lblPath)
            .Add(lblAt)
            .Add(lblEveryDay)
        End With

        With textboxes
            .Add(txtArgs)
            .Add(txtPath)
        End With

        With rbuttons
            .Add(rbtn1Day)
            .Add(rbtnUpdateAll)
        End With

        With checkboxex
            .Add(cbEnabled)
            .Add(cbEnToday)
        End With

        With groupboxes
            .Add(lblApp)
            .Add(gbStatus)
        End With

        With comboboxes
            .Add(cbDay)
        End With

        Dim themeColors As Theme = frmMain._GetSkinColours

        For Each btn As Button In buttons

            With btn

                .BackColor = Color.FromArgb(themeColors._colours("btnBRed"), _
                                             themeColors._colours("btnBGre"), _
                                             themeColors._colours("btnBBlu"))

                .FlatAppearance.MouseOverBackColor = Color.FromArgb(themeColors._colours("btnMOBRed"), _
                                     themeColors._colours("btnMOBGre"), _
                                     themeColors._colours("btnMOBBlu"))

                .FlatAppearance.MouseDownBackColor = Color.FromArgb(themeColors._colours("btnMDBRed"), _
                                     themeColors._colours("btnMDBGre"), _
                                     themeColors._colours("btnMDBBlu"))

                .FlatAppearance.BorderColor = Color.FromArgb(themeColors._colours("btnMOBRed"), _
                                                             themeColors._colours("btnMOBGre"), _
                                                             themeColors._colours("btnMOBBlu"))

                .ForeColor = Color.FromArgb(themeColors._colours("btnFRed"), _
                                             themeColors._colours("btnFGre"), _
                                             themeColors._colours("btnFBlu"))

                .Refresh()

            End With
            GC.Collect()
        Next

        For Each lbl As Label In labels

            With lbl

                .ForeColor = Color.FromArgb(themeColors._colours("lblFRed"), _
                                             themeColors._colours("lblFGre"), _
                                             themeColors._colours("lblFBlu"))

                .BackColor = Color.FromArgb(themeColors._colours("lblBRed"), _
                                             themeColors._colours("lblBGre"), _
                                             themeColors._colours("lblBBlu"))

                .Refresh()

            End With

            GC.Collect()

        Next

        For Each gb As GroupBox In groupboxes

            With gb

                .ForeColor = Color.FromArgb(themeColors._colours("lblFRed"), _
                                             themeColors._colours("lblFGre"), _
                                             themeColors._colours("lblFBlu"))

                .BackColor = Color.FromArgb(themeColors._colours("lblBRed"), _
                             themeColors._colours("lblBGre"), _
                             themeColors._colours("lblBBlu"))

                .Refresh()

            End With
            GC.Collect()
        Next

        For Each rbtn As RadioButton In rbuttons

            With rbtn

                .ForeColor = Color.FromArgb(themeColors._colours("lblFRed"), _
                                             themeColors._colours("lblFGre"), _
                                             themeColors._colours("lblFBlu"))

                .Refresh()

            End With
            GC.Collect()
        Next

        For Each cb As CheckBox In checkboxex

            With cb

                .ForeColor = Color.FromArgb(themeColors._colours("lblFRed"), _
                                             themeColors._colours("lblFGre"), _
                                             themeColors._colours("lblFBlu"))
                .Refresh()
            End With
            GC.Collect()
        Next

        For Each combo As ComboBox In comboboxes

            With combo

                .ForeColor = Color.FromArgb(themeColors._colours("lblFRed"), _
                                             themeColors._colours("lblFGre"), _
                                             themeColors._colours("lblFBlu"))

                .BackColor = Color.FromArgb(themeColors._colours("lbBRed"), _
                                     themeColors._colours("lbBGre"), _
                                     themeColors._colours("lbBBlu"))

                .Refresh()
            End With
            GC.Collect()
        Next

        For Each txt As TextBox In textboxes

            With txt

                .BackColor = Color.FromArgb(themeColors._colours("lbBRed"), _
                                             themeColors._colours("lbBGre"), _
                                             themeColors._colours("lbBBlu"))

                .ForeColor = Color.FromArgb(themeColors._colours("lbFRed"), _
                                             themeColors._colours("lbFGre"), _
                                             themeColors._colours("lbFBlu"))

                .Refresh()
            End With
            GC.Collect()
        Next

        With Me
            .BackColor = Color.FromArgb(themeColors._colours("frmBRed"), _
                                             themeColors._colours("frmBGre"), _
                                             themeColors._colours("frmBBlu"))
            .ForeColor = Color.FromArgb(themeColors._colours("frmFRed"), _
                                             themeColors._colours("frmFGre"), _
                                             themeColors._colours("frmFBlu"))
            .Opacity = CDbl(themeColors._colours("Transparent")) / 100

            .Refresh()
        End With

        GC.Collect()

    End Sub

    '
    ' This function sets the location of the form.
    '
    Private Sub position(ByVal pos As String)

        If pos = "br" Then
            Dim x As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - Me.Width
            Dim y As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - Me.Height

            Me.Location = New Point(x, y)


        ElseIf pos = "bl" Then
            Dim x As Integer = My.Computer.Screen.Bounds.Width - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width
            Dim y As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - Me.Height

            Me.Location = New Point(x, y)


        Else
            Dim x As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - Me.Width
            Dim y As Integer = My.Computer.Screen.Bounds.Height - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height

            Me.Location = New Point(x, y)

        End If
        GC.Collect()
    End Sub

    Private Sub Setting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        rbtnUpdateAll.Location = New Point((gbStatus.Width / 2) - rbtnUpdateAll.Width / 2, rbtnUpdateAll.Location.Y)

        '
        ' Save context of time if we are editing a launchie
        '
        If tempName <> "" Then
            tempTime2 = New SMTWTFS()
            For i As Integer = 0 To 6

                tempTime2.setday(i, tempTime.day(i))

            Next
        End If

        '
        ' Setup the form
        '
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        position(My.Settings.PositionRealitive)

        '
        ' Get the friendly name to show to the user.
        '
        If txtPath.Text <> "" Then

            Dim shortName() As String

            '
            ' Add the file to the list and add the user selected time. 
            '

            shortName = tempName.Split("\"c)

            If shortName(shortName.Count - 1).Length > 20 Then
                lblApp.Text = ("Settings for: " & shortName(shortName.Count - 1).Substring(0, 15) & "...")
            Else
                lblApp.Text = ("Settings for: " & shortName(shortName.Count - 1))
            End If

            If shortName(shortName.Count - 1) = "" Then
                If tempName.Length > 20 Then
                    lblApp.Text = ("Settings for: " & tempName.Substring(0, 15) & "...")
                Else
                    lblApp.Text = ("Settings for: " & tempName)
                End If
            End If



        Else

            '
            ' If new application set temp times are set accordingly:
            '       use the following example time 11:51:00 PM
            '
            '           if the minutes + 10 are more than 50 then{ 
            '
            '               if the hours + 1 are more than 11:00 PM then{ change the hours to 12:00 AM  
            '
            '               }else{ add 1 to the hours.
            '
            '               } //end if
            '
            '           }else{ add 10 to the minutes.
            '
            '           } //end if
            '
            '       thus the output would be 00:51:00 or 12:51:00 AM.    
            '
            If (Minute(Now) + 10) > 50 Then

                If (Hour(Now) + 1) > 23 Then

                    Dim temp As String = "00" & ":" & Minute(Now) & ":" & Second(Now)
                    tempTime = New SMTWTFS(temp, temp, temp, temp, temp, temp, temp, _
                                           True, True, True, True, True, True, True)
                    cbDay.SelectedIndex = Today.DayOfWeek
                Else

                    Dim temp As String = Hour(Now) + 1 & ":" & Minute(Now) & ":" & Second(Now)
                    tempTime = New SMTWTFS(temp, temp, temp, temp, temp, temp, temp, _
                                           True, True, True, True, True, True, True)
                    cbDay.SelectedIndex = Today.DayOfWeek
                End If

            Else

                Dim temp As String = Hour(Now) & ":" & Minute(Now) + 10 & ":" & Second(Now)
                tempTime = New SMTWTFS(temp, temp, temp, temp, temp, temp, temp, _
                                       True, True, True, True, True, True, True)
                cbDay.SelectedIndex = Today.DayOfWeek
            End If


        End If

        cbEnabled.Checked = tempEnabled
        lblEveryDay.Hide()

        '
        ' Reset passed
        '
        passed = False

        skin()

    End Sub


    Private Sub btnGetPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetPath.Click
        '
        ' Set the filter and then display the file selector window.
        '
        OFDSettings.Filter() = _
        "All files (*.*)|*.*|" & _
        " JPEG (*.jpg)|*.jpg|" & _
        " MP3 (*.mp3)|*.mp3|" & _
        " Playlist (*.m3u)|*.m3u|" & _
        " Applications (*.exe)|*.exe"

        OFDSettings.FileName = ""
        OFDSettings.AutoUpgradeEnabled = True
        OFDSettings.ShowDialog()

    End Sub

    Private Sub OK_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OFDSettings.FileOk
        txtPath.Clear()
        txtPath.Text = OFDSettings.FileName

        Dim shortName() As String

        '
        ' Add the file to the list and add the user selected time. 
        '

        shortName = txtPath.Text.Split("\"c)
        lblApp.Text = ("Settings for: " & shortName(shortName.Count - 1))
        cbEnabled.Checked = True
        Me.Show()

    End Sub

    Private Sub OK_dis(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OFDSettings.Disposed

        passed = False

        Me.Close()
        frmMain.Show()

    End Sub

    Protected Friend Sub ok()

        '
        ' Make sure the user entered something to launch
        '
        If txtPath.Text <> "" Then

            '
            ' Make sure the user clicked SAVE
            '
            If passed = True Then

                '
                ' Check that the file or directory exists.
                '
                If (System.IO.File.Exists(txtPath.Text) Or System.IO.Directory.Exists(txtPath.Text)) Then

                    '
                    ' Set the time values into the SMTWTFS class and add it to the ATEA class
                    '

                    Dim temp As ATEA
                    If time Then
                        SetTime()
                        temp = New ATEA(txtPath.Text, cbEnabled.Checked, txtArgs.Text, tempTime, False)
                    Else
                        temp = New ATEA(txtPath.Text, cbEnabled.Checked, txtArgs.Text, New SMTWTFS, True)
                    End If


                    '
                    ' Add the value to the main array.
                    '
                    frmMain.updateArray(temp)
                    OFDSettings.FileName = ""

                    '
                    ' Set the correct buttons on the main form
                    '
                    frmMain.btnRemove.Enabled = False
                    frmMain.btnClear.Enabled = True

                    '
                    ' Select null in the listbox on the main form
                    '
                    frmMain.lbLaunchers.SelectedIndex = -1

                Else

                    '
                    ' Temp value for message box
                    '
                    Dim i As Integer

                    i = MsgBox("The file or folder you specified does not exist! Are you sure you want to continue?", MsgBoxStyle.YesNo, "Warning:")

                    '
                    ' Save if the user says to.
                    '
                    If i = MsgBoxResult.Yes Then

                        Dim temp As ATEA
                        If time Then
                            temp = New ATEA(txtPath.Text, cbEnabled.Checked, txtArgs.Text, tempTime, False)
                        Else
                            temp = New ATEA(txtPath.Text, cbEnabled.Checked, txtArgs.Text, New SMTWTFS, True)
                        End If

                        frmMain.updateArray(temp)
                        OFDSettings.FileName = ""

                        frmMain.btnRemove.Enabled = False
                        frmMain.btnClear.Enabled = True

                        frmMain.lbLaunchers.SelectedIndex = -1

                    End If

                End If

            Else

                '
                ' Restore context
                '
                SetTime()

                Dim temp As ATEA
                If time Then
                    temp = New ATEA(txtPath.Text, cbEnabled.Checked, txtArgs.Text, tempTime2, False)
                Else
                    temp = New ATEA(txtPath.Text, cbEnabled.Checked, txtArgs.Text, New SMTWTFS, True)
                End If

                frmMain.updateArray(temp)
                OFDSettings.FileName = ""


                frmMain.btnRemove.Enabled = False
                frmMain.btnClear.Enabled = True

                frmMain.lbLaunchers.SelectedIndex = -1


            End If


        End If




    End Sub

    Private Sub Form1_close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosed

        '
        ' Hide and save
        '
        ok()
        frmMain.SaveToFile()
        frmMain.lbLaunchers.SelectedIndex = -1
        frmMain.btnRemove.Enabled = False
        frmMain.btnEdit.Enabled = False

    End Sub

    Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click
        passed = True
        Me.Close()
        frmMain.pnlupdwn.Hide()

        If frmMain.lbLaunchers.Items.Count > 8 Then
            frmMain.pnlupdwn.Show()
        End If
        frmMain.Show()
        Me.Dispose()
        MemoryManagement.FlushMemory()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        My.Settings.Egg = 0
        If My.Settings.Egg = 0 Then

            My.Settings.Egg = 1

        End If
        txtPath.Text = tempName
        txtArgs.Text = tempArg
        passed = False
        Me.Close()
        frmMain.Show()
        Me.Dispose()
        MemoryManagement.FlushMemory()
    End Sub

    Private Sub cbAll_checked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnUpdateAll.CheckedChanged

        If rbtnUpdateAll.Checked Then

            rbtn1Day.Text = "Modify &one day"
            cbDay.Enabled = False
            cbDay.Hide()
            lblEveryDay.Show()
            cbEnToday.Text = "Will launch &all days"
            rbtn1Day.Location = New Point((gbStatus.Width / 2) - rbtn1Day.Width / 2, rbtn1Day.Location.Y)

        Else

            rbtn1Day.Text = "Modify &one day"
            rbtn1Day.Location = New Point((gbStatus.Width / 2) - rbtn1Day.Width / 2, rbtn1Day.Location.Y)
            cbDay.Enabled = True
            cbDay.Show()
            lblEveryDay.Hide()

            cbEnToday.Text = "Will launch: " & cbDay.Text.ToLower

        End If

    End Sub

    Private Sub cbDay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbDay.SelectedIndexChanged

        If cbDay.SelectedIndex <> -1 Then
            Dim SplitT() As String
            Dim t As String = tempTime.day(cbDay.SelectedIndex)
            Dim tempT As String
            Dim AMPM As String
            SplitT = t.Split(":"c)


            If CInt(SplitT(0)) >= 12 Then
                AMPM = "PM"
                SplitT(0) = CStr(CInt(SplitT(0)) - 12)

            Else
                If CInt(SplitT(0)) = 0 Then
                    SplitT(0) = CStr(CInt(SplitT(0)) + 12)
                End If

                AMPM = "AM"
            End If

            If SplitT(1) > 59 Then
                SplitT(1) -= 10
            End If
            If SplitT(2) > 59 Then
                SplitT(2) -= 10
            End If

            tempT = SplitT(0) & ":" & SplitT(1) & ":" & SplitT(2) & " " & AMPM
            dtpSetTime.Text = tempT
            cbEnToday.Text = "Will launch: " & cbDay.Text.ToLower
            cbEnToday.Location = New Point((gbStatus.Width / 2) - cbEnToday.Width / 2, cbEnToday.Location.Y)
            cbEnToday.Checked = tempTime.eday(cbDay.SelectedIndex)
            rbtn1Day.Text = "Modify &one day"

        End If

    End Sub

    '
    ' This updates the time in the SMTWTFS class from the date time picker.
    ' 
    Private Sub SetTime() _
    Handles _
    rbtn1Day.CheckedChanged, rbtnUpdateAll.CheckedChanged, dtpSetTime.Click, cbEnToday.CheckedChanged

        '
        ' See if the user just wants to update 1 day
        '
        If rbtn1Day.Checked Then

            '
            ' Make sure that the user has selected a day.
            '
            If cbDay.SelectedIndex <> -1 Then

                '
                ' See if it is AM or PM
                '
                If dtpSetTime.Text.EndsWith("PM") Then

                    '
                    ' Temp values
                    '
                    Dim timeA() As String
                    Dim timeB() As String
                    Dim hours As String
                    Dim min As String
                    Dim sec As String

                    '
                    ' Splitting the string of the date time picker and then getting the seconds
                    '
                    timeA = dtpSetTime.Text.Split(":"c)
                    timeB = timeA(2).Split(" "c)

                    '
                    ' Setting the correct values
                    '
                    hours = timeA(0)
                    min = timeA(1)
                    sec = timeB(0)

                    '
                    ' Correcting for 24 hour clock
                    '
                    If CInt(hours) > 12 Then
                        tempTime.setday(cbDay.SelectedIndex, CInt(hours) - 12 & ":" & min & ":" & sec)
                    ElseIf CInt(hours) = 12 Then
                        tempTime.setday(cbDay.SelectedIndex, CInt(hours) & ":" & min & ":" & sec)
                    Else
                        tempTime.setday(cbDay.SelectedIndex, CInt(hours) + 12 & ":" & min & ":" & sec)
                    End If


                End If
                If dtpSetTime.Text.EndsWith("AM") Then

                    Dim timeA() As String
                    Dim timeB() As String
                    Dim hours As String
                    Dim min As String
                    Dim sec As String

                    timeA = dtpSetTime.Text.Split(":"c)
                    timeB = timeA(2).Split(" "c)

                    hours = timeA(0)
                    min = timeA(1)
                    sec = timeB(0)

                    If CInt(hours) <> 12 Then
                        tempTime.setday(cbDay.SelectedIndex, CInt(hours) & ":" & min & ":" & sec)
                    Else
                        tempTime.setday(cbDay.SelectedIndex, CInt(hours) - 12 & ":" & min & ":" & sec)
                    End If

                End If
                tempTime.esetday(cbDay.SelectedIndex, cbEnToday.Checked)
            End If

        ElseIf rbtnUpdateAll.Checked Then
            For i As Integer = 0 To 6
                If dtpSetTime.Text.EndsWith("PM") Then

                    Dim timeA() As String
                    Dim timeB() As String
                    Dim hours As String
                    Dim min As String
                    Dim sec As String

                    timeA = dtpSetTime.Text.Split(":"c)
                    timeB = timeA(2).Split(" "c)

                    hours = timeA(0)
                    min = timeA(1)
                    sec = timeB(0)

                    If CInt(hours) > 12 Then
                        tempTime.setday(i, CInt(hours) - 12 & ":" & min & ":" & sec)
                    ElseIf CInt(hours) = 12 Then
                        tempTime.setday(i, CInt(hours) & ":" & min & ":" & sec)
                    Else
                        tempTime.setday(i, CInt(hours) + 12 & ":" & min & ":" & sec)
                    End If

                End If
                If dtpSetTime.Text.EndsWith("AM") Then

                    Dim timeA() As String
                    Dim timeB() As String
                    Dim hours As String
                    Dim min As String
                    Dim sec As String

                    timeA = dtpSetTime.Text.Split(":"c)
                    timeB = timeA(2).Split(" "c)

                    hours = timeA(0)
                    min = timeA(1)
                    sec = timeB(0)

                    If CInt(hours) <> 12 Then
                        tempTime.setday(i, CInt(hours) & ":" & min & ":" & sec)
                    Else
                        tempTime.setday(i, CInt(hours) - 12 & ":" & min & ":" & sec)
                    End If

                End If
                tempTime.esetday(i, cbEnToday.Checked)
            Next

        End If
        GC.Collect()
    End Sub

    Private Sub txtPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPath.Click

        If txtPath.Text = "" Then

            '
            ' Set the filter and then display the file selector window.
            '
            OFDSettings.Filter() = _
            "All files (*.*)|*.*|" & _
            " JPEG (*.jpg)|*.jpg|" & _
            " MP3 (*.mp3)|*.mp3|" & _
            " Playlist (*.m3u)|*.m3u|" & _
            " Applications (*.exe)|*.exe"

            OFDSettings.FileName = ""
            OFDSettings.AutoUpgradeEnabled = True
            OFDSettings.ShowDialog()

        End If

    End Sub

    Private Sub btnWindows_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWindows.Click
        Me.Width = 311
        cbEnabled.Enabled = False
        cbEnabled.Checked = True
        gbStatus.Hide()
        Panel1.Hide()
        time = False
        btnSet.Enabled = True
    End Sub

    Private Sub btnTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTime.Click
        Me.Width = 622
        position(My.Settings.PositionRealitive)
        gbStatus.Show()
        Panel1.Hide()
        time = True
        btnSet.Enabled = True
    End Sub
End Class